package org.apache.james.mime4j.field.language;

import org.apache.james.mime4j.MimeException;

public class ParseException extends MimeException
{
  public Token currentToken;
  protected String eol;
  public int[][] expectedTokenSequences;
  protected boolean specialConstructor;
  public String[] tokenImage;

  public ParseException()
  {
    super("Cannot parse field");
    this.eol = System.getProperty("line.separator", "\n");
    this.specialConstructor = false;
  }

  public ParseException(String paramString)
  {
    super(paramString);
    this.eol = System.getProperty("line.separator", "\n");
    this.specialConstructor = false;
  }

  public ParseException(Throwable paramThrowable)
  {
    this(paramThrowable.getMessage());
    initCause(paramThrowable);
  }

  public ParseException(Token paramToken, int[][] paramArrayOfInt, String[] paramArrayOfString)
  {
    super("Cannot parse field");
    this.eol = System.getProperty("line.separator", "\n");
    this.specialConstructor = true;
    this.currentToken = paramToken;
    this.expectedTokenSequences = paramArrayOfInt;
    this.tokenImage = paramArrayOfString;
  }

  protected String add_escapes(String paramString)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0;
    if (i < paramString.length())
    {
      char c;
      switch (paramString.charAt(i))
      {
      default:
        c = paramString.charAt(i);
        if ((c < ' ') || (c > '~'))
        {
          String str = "0000" + Integer.toString(c, 16);
          localStringBuffer.append("\\u" + str.substring(str.length() - 4, str.length()));
        }
      case '\0':
      case '\b':
      case '\t':
      case '\n':
      case '\f':
      case '\r':
      case '"':
      case '\'':
      case '\\':
      }
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      while (true)
                      {
                        while (true)
                          ++i;
                        localStringBuffer.append("\\b");
                      }
                      localStringBuffer.append("\\t");
                    }
                    localStringBuffer.append("\\n");
                  }
                  localStringBuffer.append("\\f");
                }
                localStringBuffer.append("\\r");
              }
              localStringBuffer.append("\\\"");
            }
            localStringBuffer.append("\\'");
          }
          localStringBuffer.append("\\\\");
        }
        localStringBuffer.append(c);
      }
    }
    return localStringBuffer.toString();
  }

  public String getMessage()
  {
    String str4;
    String str5;
    if (!(this.specialConstructor))
    {
      str5 = super.getMessage();
      return str5;
    }
    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0;
    for (int j = 0; j < this.expectedTokenSequences.length; ++j)
    {
      if (i < this.expectedTokenSequences[j].length)
        i = this.expectedTokenSequences[j].length;
      for (int l = 0; l < this.expectedTokenSequences[j].length; ++l)
        localStringBuffer.append(this.tokenImage[this.expectedTokenSequences[j][l]]).append(" ");
      if (this.expectedTokenSequences[j][(this.expectedTokenSequences[j].length - 1)] != 0)
        localStringBuffer.append("...");
      localStringBuffer.append(this.eol).append("    ");
    }
    String str1 = "Encountered \"";
    Token localToken = this.currentToken.next;
    int k = 0;
    if (k < i)
    {
      if (k != 0)
        str1 = str1 + " ";
      if (localToken.kind != 0)
        break label382;
      str1 = str1 + this.tokenImage[0];
    }
    String str2 = str1 + "\" at line " + this.currentToken.next.beginLine + ", column " + this.currentToken.next.beginColumn;
    String str3 = str2 + "." + this.eol;
    if (this.expectedTokenSequences.length == 1)
      str4 = str3 + "Was expecting:" + this.eol + "    ";
    while (true)
    {
      while (true)
      {
        while (true)
          str5 = str4 + localStringBuffer.toString();
        label382: str1 = str1 + add_escapes(localToken.image);
        localToken = localToken.next;
        ++k;
      }
      str4 = str3 + "Was expecting one of:" + this.eol + "    ";
    }
  }
}